package com.hntxk.cqzd.consultation.service.impl;


import com.hntxk.core.framework.service.impl.BaseServiceImpl;
import com.hntxk.cqzd.common.service.CommonFileService;
import com.hntxk.cqzd.consultation.entity.TblDibFile;
import com.hntxk.cqzd.consultation.service.DibFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author <a href="huangbiquan@hotmail.com">Huang.Biquan</a>
 * @Description: 基本信息管理接口实现类 <br>
 * @Project: SP <br>
 * @date 2019/6/3 10:01 <br>
 */
@Service("dibFileManageService")
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class DibFileServiceImpl extends BaseServiceImpl<TblDibFile> implements DibFileService {

    @Autowired
    @Qualifier("commonFileServiceImpl")
    private CommonFileService commonFileService;

    public static String DIBFILE_MAPPER_NAMESPACE = "com.hntxk.cqzd.consultation.mapper.DibFileMapper.";

    public DibFileServiceImpl() {
        super(DIBFILE_MAPPER_NAMESPACE);
    }

    @Override
    public List<TblDibFile> getByFkId(Long id) {
        TblDibFile tblDibFile=new TblDibFile();
        tblDibFile.setDibId(id);
        List<TblDibFile> query = (List<TblDibFile>) query(DIBFILE_MAPPER_NAMESPACE + "getByFkId", tblDibFile);
        return query;
    }

    @Override
    public ResponseEntity<byte[]> getFile(String fileCode) {
        TblDibFile tblDibFile = get(DIBFILE_MAPPER_NAMESPACE + "getByFlieCode", fileCode);
        tblDibFile.setFileDownloadNo(tblDibFile.getFileDownloadNo()+1);
       update(DIBFILE_MAPPER_NAMESPACE+"update",tblDibFile);
        String filePath=tblDibFile.getFileAddress();
        String fileName = tblDibFile.getFileName();
        return  commonFileService.getFile(filePath,fileName);

    }
}
